﻿#include "manplugin.h"
#include "src/DAO/clouds/daocloudsmock.h"
#include "src/DAO/versions/versioncmd.h"
#include "src/DAO/versions/versionjson.h"
#include "src/middle/config/globals.h"
#include "src/middle/managers/manglobal.h"
#include "src/middle/logs/loggerqdebug.h"
#include "src/DAO/clouds/daocloudscos.h"

using namespace GLOBAL;

ManPlugin::ManPlugin(QObject *parent): QObject{parent} {}

ManPlugin::~ManPlugin()
{
    delete m_clouds;
    delete m_version;
    qDebug("delete ManPlugins ");
}

void ManPlugin::installPlugins(int argc, char *argv[])
{
    // 设置版本信息 DAO 插件
    VersionCmd version(argc, argv);
    if (version.isValid()) {
        m_version = new VersionCmd(argc, argv);
    } else {
        m_version = new VersionJson(VERSION::JSON_PATH);
    }
    m_version->setVersion();

    // 设置日志器插件
    mLogIns->setLogger(new LoggerQDebug());
    mLogIns->setLevel(GLOBAL::LOG_LEVEL::TOTAL); // 必要时修改日志等级

    // 设置对象存储 DAO 插件
    if (m_version->major() == VERSION::MAJOR_BUSINESS) {
        m_clouds = new DaoCloudsCos();
    } else {
        m_clouds = new DaoCloudsMock(":/static/testing/custom.json");
    }
}

DaoClouds *ManPlugin::clouds() const
{
    return m_clouds;
}
